package cn.iocoder.yudao.module.member.dal.mysql.user;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.UserExportReqVO;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.UserPageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 会员 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface AdUserMapper extends BaseMapperX<UserDO> {

    default PageResult<UserDO> selectPage(UserPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserDO>()
                .likeIfPresent(UserDO::getNickname, reqVO.getName())
                .likeIfPresent(UserDO::getNickname, reqVO.getNickname())
                .eqIfPresent(UserDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(UserDO::getStatus, reqVO.getStatus())
                .eqIfPresent(UserDO::getType, reqVO.getType())
                .eqIfPresent(UserDO::getMobile, reqVO.getMobile())
                .eqIfPresent(UserDO::getPassword, reqVO.getPassword())
                .eqIfPresent(UserDO::getRegisterIp, reqVO.getRegisterIp())
                .eqIfPresent(UserDO::getLoginIp, reqVO.getLoginIp())
                .betweenIfPresent(UserDO::getLoginDate, reqVO.getLoginDate())
                .eqIfPresent(UserDO::getGender, reqVO.getGender())
                .eqIfPresent(UserDO::getUnionId, reqVO.getUnionId())
                .eqIfPresent(UserDO::getOpenId, reqVO.getOpenId())
                .eqIfPresent(UserDO::getAppId, reqVO.getAppId())
                .betweenIfPresent(UserDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(UserDO::getId));
    }

    default List<UserDO> selectList(UserExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<UserDO>()
                .likeIfPresent(UserDO::getNickname, reqVO.getName())
                .likeIfPresent(UserDO::getNickname, reqVO.getNickname())
                .eqIfPresent(UserDO::getAvatar, reqVO.getAvatar())
                .eqIfPresent(UserDO::getStatus, reqVO.getStatus())
                .eqIfPresent(UserDO::getType, reqVO.getType())
                .eqIfPresent(UserDO::getMobile, reqVO.getMobile())
                .eqIfPresent(UserDO::getPassword, reqVO.getPassword())
                .eqIfPresent(UserDO::getRegisterIp, reqVO.getRegisterIp())
                .eqIfPresent(UserDO::getLoginIp, reqVO.getLoginIp())
                .betweenIfPresent(UserDO::getLoginDate, reqVO.getLoginDate())
                .eqIfPresent(UserDO::getGender, reqVO.getGender())
                .eqIfPresent(UserDO::getUnionId, reqVO.getUnionId())
                .eqIfPresent(UserDO::getOpenId, reqVO.getOpenId())
                .eqIfPresent(UserDO::getAppId, reqVO.getAppId())
                .betweenIfPresent(UserDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(UserDO::getId));
    }

}
